package es.decloud.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name = "usuario_aviso")
public class UsuarioAviso extends BaseObject implements Serializable {

	private static final long serialVersionUID = -5361475683942650167L;

	private Long id;
	private Usuario usuario;
	private Aviso aviso;
	private boolean visible;

	public UsuarioAviso() {
	}

	public UsuarioAviso(Usuario usuario, Aviso aviso, boolean visible) {
		this.usuario = usuario;
		this.aviso = aviso;
		this.visible = visible;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "usuario_id", nullable = false)
	public Usuario getUsuario() {
		return this.usuario;
	}

	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	@ManyToOne
	@JoinColumn(name = "aviso_id", nullable = false)
	public Aviso getAviso() {
		return this.aviso;
	}

	public void setAviso(Aviso aviso) {
		this.aviso = aviso;
	}

	@Column(name = "visible", nullable = false)
	public boolean isVisible() {
		return this.visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((aviso == null) ? 0 : aviso.hashCode());
		result = prime * result + ((usuario == null) ? 0 : usuario.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UsuarioAviso other = (UsuarioAviso) obj;
		if (aviso == null) {
			if (other.aviso != null)
				return false;
		}
		else if (!aviso.equals(other.aviso))
			return false;
		if (usuario == null) {
			if (other.usuario != null)
				return false;
		}
		else if (!usuario.equals(other.usuario))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id).append("usuario", usuario).append("aviso", aviso)
				.append("visible", visible).toString();
	}

}
